<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Controllers\HandleRedis;
use App\Models\gonggao;
use App\Models\u_all_record;
use App\Models\u_bet_front_mas;
use App\Models\u_chat;
use App\Models\u_current_list;
use App\Models\u_xianhong;

/**
 * 关于桌台的
 * Class TableController
 * @package App\Http\Controllers\Api
 */
class TableController extends Controller
{
    /**
     * 获取所有限红
     */
    public function getAllXianhong()
    {
        $this->sendToClient(['code' => 200, 'f' => self::$f, 'data' => u_xianhong::getAllXianhong()]);
    }

    /**
     * 获取所有台子
     */
    public function getAllTable()
    {
        $this->sendToClient(['code' => 200, 'f' => self::$f, 'data' => HandleRedis::getAllResultData()]);
    }

    /**
     * 获取单条公告信息
     */
    public function getGonggao()
    {
        $this->sendToClient(['code' => 200, 'f' => self::$f, 'data' => gonggao::getGonggao()]);
    }

    /**
     * 获取公告信息
     */
    public function getAllGonggao()
    {
        $this->sendToClient(['code' => 200, 'f' => self::$f, 'data' => gonggao::getAllGonggao()]);
    }

    /**
     * 获取历史数据
     * @param int page
     * @param int limit
     */
    public function getAllRecord()
    {
        $this->sendToClient([
            'code' => 200,
            'f' => self::$f,
            'data' => u_all_record::getAllRecord(self::$page, self::$limit)
        ]);
    }

    /**
     * 获取历史列表聊天
     * @param int pid (u_all_record->id)
     * @param int showhao (showhaoid)
     */
    public function getHistoryChat()
    {
        $this->sendToClient([
            'code' => 200,
            'f' => self::$f,
            'data' => u_chat::getChatByPidAndShowhao(self::$pid, self::$showhao)
        ]);
    }

    /**
     * 获取投注
     * @param int pid (u_all_record->id || u_current_list->pid)
     * @param int showhao (showhaoid)
     */
    public function getBet()
    {
        $data = u_all_record::getRecordByIdAndShowhao(
            self::$pid,
            self::$showhao,
            'ju,room'
        );
        $cnt = u_current_list::getCurrentListByPidAndRoom(self::$pid, self::$room);
        $data['cnt'] = $cnt;
        $data['zall'] = array_sum(array_column($cnt,'Z'));
        $data['xall'] = array_sum(array_column($cnt,'x'));
        $data['hall'] = array_sum(array_column($cnt,'H'));
        $data['Jall'] = array_sum(array_column($cnt,'J'));
        $data['Kall'] = array_sum(array_column($cnt,'K'));
        $this->sendToClient(['code' => 200, 'f' => self::$f, 'data' => $data]);
    }

    /**
     * 获取玩家资料
     * @param int pid (u_all_record->id || u_bet_front_mas->pid)
     * @param int showhao (showhaoid)
     */
    public function getPlayer()
    {
        $data = u_all_record::getRecordByIdAndShowhao(
            self::$pid,
            self::$showhao
        );
        $data['cnt'] = u_bet_front_mas::getAllBetFrontMas(self::$pid,$data['room']);
        $this->sendToClient(['code' => 200, 'f' => self::$f, 'data' => $data]);
    }
}
